<template>
	<view>
		<view class="navbar-content">
			<uni-icons @click="back" style="margin-right: 10rpx;" type="arrowleft" size="25"
				color="#252525"></uni-icons>
			<view class="navbar-search">
				<view class="navbar-search_icon" @click="toSearch">
					<uni-icons type="search" size="16" color="#999"></uni-icons>
				</view>
				<view class="navbar-serach" style="width: 100%;">
					<input @click="toSearch" disabled class="navbar-search_text" confirm-type="search" type="text"
						v-model="searchKey" placeholder="请输入您要搜索的内容" />
				</view>
			</view>
		</view>
		<view class="classfiy" v-for="(i,k) in goodsList" :key="k" @click="$u.route('pages/product/list?bId=' + i.brandId)">
			<view class="logo">
				<image :src="i.h5LogoUrl" mode="widthFix"></image>
				<view>{{i.instructions}}</view>
			</view>
			<view class="product">
				<block v-if="i.goodsList.length > 0 && i.goodsList">
					<view class="product_item" v-for="(a,b) in i.goodsList.slice(0,2)" @click.stop="$u.route('pages/product/product?id=' + a.goodsId )">
						<image :src="a.goodsImage" mode=""></image>
						<view class="product_item_name">{{a.goodsName}}</view>
						<view class="product_item_price" v-if="isShowPriceUnlogin==1||hasLogin">￥{{a.goodsPrice|money}}</view>
						<view class="product_item_price" v-else>******</view>
					</view>
				</block>
				<u-empty v-else style="margin: auto;" text="暂无商品信息"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		getAllHotBrandList
	} from '../../api/index/index.js'
	export default {
		data() {
			return {
				searchKey: '',
				goodsList: [],
				isShowPriceUnlogin: uni.getStorageSync('isShowPriceUnlogin')||0
			}
		},
		computed: {
			...mapState(['hasLogin'])
		},
		onLoad() {
			this.loadData()
		},
		onPullDownRefresh() {
			this.loadData('refresh')
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			toSearch() {
				uni.navigateTo({
					url: `/pages/search/search`
				})
			},
			async loadData(type) {
				uni.showLoading({ title: '加载中...' });
				let ending = () =>{
					uni.hideLoading();
					if(type === 'refresh')uni.stopPullDownRefresh();
				}
				try{
					let res = await getAllHotBrandList();
					this.goodsList = res.data;
					ending();
				}catch(e){
					ending()
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: $page-color-base;
		height: 100%;
	}
	.navbar-content {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 0 30rpx 0 16rpx;
		height: 45px;
		box-sizing: border-box;
		
		.navbar-search {
			display: flex;
			align-items: center;
			padding: 0 20rpx;
			width: 100%;
			height: 30px;
			border-radius: 40rpx;
			background-color: #fff;
			border: 1px solid red;
		
			.navbar-search_icon {
				// width: 10px;
				// height: 10px;
				margin-right: 10rpx;
			}
		
			.navbar-search_text {
				width: 100%;
				font-size: $my-font-size-middle;
				color: #999;
			}
		}
		
		&.search {
			padding-left: 0;
		
			.navbar-content__search-icons {
				margin-left: 10px;
				margin-right: 10px;
			}
		
			.navbar-search {
				border-radius: 5px;
			}
		}
	}
	.classfiy{
		// background-color: #dfedff;
		margin: 20rpx;
		height: 220rpx;
		border-radius: 24rpx;
		display: flex;
		justify-content: space-between;
		
		&:nth-child(n){
			background-color: #dfedff;
		}
		&:nth-child(2n){
			background-color: #f1fbfe;
		}
		&:nth-child(3n){
			background-color: #ffeff0;
		}
		.logo{
			width: 33%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			image{
				width: 140rpx;
				height: 60rpx;
				border-radius: 10rpx;
			}
			
			view{
				width: 100%;
				padding: 0 20rpx;
				text-align: center;
				margin-top: 6rpx;
				color: #7f7f7f;
				font-size:24rpx;
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
			}
		}
		.product{
			width: 66%;
			background-color: #fff;
			border-radius: 24rpx;
			display: flex;
			justify-content: space-between;
			&_item{
				width: 50%;
				padding: 15rpx;
				text-align: center;
				font-size: 24rpx;
				image{
					border-radius: 10rpx;
					width: 120rpx;
					height: 120rpx;
					vertical-align: middle;
				}
				
				&_name{
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				
				&_price{
					color: #fa436a;
				}
			}
		}
	}
</style>
